package ooday04;

public class Test {
    public static void main(String[] args) {
        Person[] ps = new Person[5];
        //向上造型
        ps[0] = new Student("zhangSan", 25, "lf", "111");
        ps[1] = new Student("liSi", 23, "fd", "222");
        ps[2] = new Teacher("ww", 74, "bc", 4555);
        ps[3] = new Teacher("xl", 45, "ag", 1234);
        ps[4] = new Doctor("ad", 45, "ag", "主任");
        for (int i = 1; i < ps.length; i++) {
            System.out.println(ps[i].name);
            ps[i].sayHi();
        }
        //1.能点出来什么，看引用的类型
        //2.重写方法被调用时，看对象的类型
        Student zs = new Student("张三", 24, "lf", "111");
        zs.sayHi();//调用student类的sayHi方法
        Person p = new Student("李四", 25, "fs", "112");
        p.sayHi();//调用Student类的sayHi()方法
    }
}
